\doxysection{x\+Semaphore\+Create\+Mutex }
\hypertarget{group__x_semaphore_create_mutex}{}\label{group__x_semaphore_create_mutex}\index{xSemaphoreCreateMutex@{xSemaphoreCreateMutex}}
semphr. h 
\begin{DoxyPre}SemaphoreHandle\_t xSemaphoreCreateMutex( void )\end{DoxyPre}


Creates a new mutex type semaphore instance, and returns a handle by which the new mutex can be referenced.

Internally, within the Free\+RTOS implementation, mutex semaphores use a block of memory, in which the mutex structure is stored. If a mutex is created using x\+Semaphore\+Create\+Mutex() then the required memory is automatically dynamically allocated inside the x\+Semaphore\+Create\+Mutex() function. (see \href{http://www.freertos.org/a00111.html}{\texttt{http\+://www.\+freertos.\+org/a00111.\+html}}). If a mutex is created using x\+Semaphore\+Create\+Mutex\+Static() then the application writer must provided the memory. x\+Semaphore\+Create\+Mutex\+Static() therefore allows a mutex to be created without using any dynamic memory allocation.

Mutexes created using this function can be accessed using the x\+Semaphore\+Take() and x\+Semaphore\+Give() macros. The x\+Semaphore\+Take\+Recursive() and x\+Semaphore\+Give\+Recursive() macros must not be used.

This type of semaphore uses a priority inheritance mechanism so a task \textquotesingle{}taking\textquotesingle{} a semaphore MUST ALWAYS \textquotesingle{}give\textquotesingle{} the semaphore back once the semaphore it is no longer required.

Mutex type semaphores cannot be used from within interrupt service routines.

See x\+Semaphore\+Create\+Binary() for an alternative implementation that can be used for pure synchronisation (where one task or interrupt always \textquotesingle{}gives\textquotesingle{} the semaphore and another always \textquotesingle{}takes\textquotesingle{} the semaphore) and from within interrupt service routines.

\begin{DoxyReturn}{Returns}
If the mutex was successfully created then a handle to the created semaphore is returned. If there was not enough heap to allocate the mutex data structures then NULL is returned.
\end{DoxyReturn}
Example usage\+: 
\begin{DoxyPre}
SemaphoreHandle\_t xSemaphore;

void vATask( void * pvParameters )
\{
   // Semaphore cannot be used before a call to xSemaphoreCreateMutex().
   // This is a macro so pass the variable in directly.
   xSemaphore = xSemaphoreCreateMutex();

   if( xSemaphore != NULL )
   \{
       // The semaphore was created successfully.
       // The semaphore can now be used.
   \}
\}
\end{DoxyPre}
 